package com.group.exceptions;

import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import pojo.vo.BaseRespVO;

@ControllerAdvice
@RestControllerAdvice
public class HandlerExceptions {

    /*捕获单个自定义异常*/
   /* @ExceptionHandler(value = UserLoginException.class)
    @ResponseBody
    public BaseRespVO handlerLoginException(UserLoginException e) {
        BaseRespVO result = new BaseRespVO();
        result.setCode(e.getErrorCode());
        result.setMsg(e.getMessage());
        return result;
    }*/

    /*捕获所有自定义异常*/
    @ExceptionHandler(value = BaseException.class)
    @ResponseBody
    public BaseRespVO handlerBaseException(BaseException e) {
        BaseRespVO result = new BaseRespVO();
        result.setCode(e.getErrorCode());
        result.setMsg(e.getMessage());
        return result;
    }

    /*捕获所有异常*/
    @ExceptionHandler(value = Exception.class)
    @ResponseBody
    public BaseRespVO handlerException(Exception e) {
        BaseRespVO result = new BaseRespVO();
        result.setCode(BaseRespVO.CodeType.FAILED.getValue());
        result.setMsg(e.getMessage());
        return result;
    }
}
